/**	\author    coidgen 0.9.2
	\version   0.1 (1.0 build 1)
	\date      
	\brief     
*/

#ifndef __COID_CLIENT__websole_h
#define __COID_CLIENT__websole_h


#define CLIENT__websole_h



#include "coid/coidclient.h"
#include "coid/comm/sync/mutex_reg.h"


extern const version COID_version_Websole_1_0;





namespace coid {


struct COID_TABLE_Websole_1_0;


////////////////////////////////////////////////////////////////////////////////
class Websole_client
{
	//NET_OPTIONS: nolog_system_calls
private:
	COID_TABLE_Websole_1_0 * _me;
	COID_TABLE_Websole_1_0 * _vtbl;
	mutable comm_mutex_custom_reg<netstream, void*> _mx_reg;
	uint _conn_data;
	uint _timeout;
	charstr _addr;

	void set_connection_type( uint ct ) {_conn_data = ct;}
	void destroy_me();

public:
	Websole_client();
	~Websole_client();
	Websole_client( const Websole_client & c );
	Websole_client & operator = ( const Websole_client & c );

	opcd ping_server( const char * coid_address, uint coid_obj_id=UMAX32, uint coid_flags=ConnectFlags::xACCESS_MODE ) const;
	bool is_connected() const;
	opcd disconnect();
	const charstr& get_addr() const {return _addr;}
	comm_mutex_reg * get_mx() {return &_mx_reg;}
	opcd get_last_error() const;
	void set_last_error( opcd e );
	uint get_connection_type() const {return _conn_data;}
	opcd set_timeout( uint milliseconds );
	uint get_timeout() const {return _timeout;}
	void setup_stream( binstream& b, uint coid_flags, uint coid_obj_id ) const;
	bool setup_members( uint coid_stream_flags, netstream * bstream, binstream * bstream2=NULL, comm_mutex_reg * mx_reg=NULL );

	static const version & get_version() { return COID_version_Websole_1_0; }


public:
	opcd connect(  const charstr & name, const password & pwd, uints * ref, const char * coid_address=NULL, uint coid_flags=ConnectFlags::xACCESS_MODE );
	opcd connect_within(  comm_mutex_reg & coid_channel, const charstr & name, const password & pwd, uints * ref );
	opcd connect_shared( uint coid_obj_id, const char * coid_address=NULL, uint coid_flags=ConnectFlags::xACCESS_MODE );

	opcd get_current_pos( uints * ref );
	opcd read( uints & ref, dynarray<token> & rows, uint & flg );
	opcd command( const charstr & cmd );
};

} // namespace coid


#endif	// ! __COID_CLIENT__websole_h
